$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        parentId:null,
        init:function () {
            this.form = new xhForm($('#xh_form'));
            this.form.parse();
            if (info) {
                this.form.fill(info);
            }
            this.parentId = xhTool.getQuery('iParentId');
            if (xhTool.getQuery('iParentId')) {
                $('[name=iParentId]').val(this.parentId);
            }
            this.listener();
        },
        listener:function () {
            var $this = this;

            $('#bt_modal_confirm', parent.document).click(function () {
                $this.funObj().formSubmit();
            })
        },
        funObj:function () {
            var $this = this;
            return {
                formSubmit:function () {
                    $this.form.submit('bpm/template/saveNode',{},function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                        if (info) {
                            window.top.xhTop.getActiveFrame().obj.table.treegrid('reload',{openId:info.iNodeId});
                        } else if ($this.parentId) {
                            window.top.xhTop.getActiveFrame().obj.table.treegrid('reload',{openId:$this.parentId});
                        } else {
                            window.top.xhTop.getActiveFrame().obj.table.treegrid('reload',{firstOpen:$('[name=iTPId]').val()});
                        }
                        window.top.xhTop.getActiveFrame().obj.table.treegrid('reload');
                        window.top.xhTop.closeModal();
                    })
                }
            }
        }
    }
};